package com.company.exp2.timeLine.impl;

import com.company.exp2.typeEnum.EventType;
import com.company.exp2.util.OrderedList;
import com.company.exp2.event.Event;
import com.company.exp2.timeLine.TimeLine;

import java.util.Comparator;

public class DefaultTimeLine extends TimeLine {

    private final OrderedList<Event> eventQueue;    //  事件队列
    private final Comparator<Event> comparator;     //

    {
        eventQueue = new OrderedList<>();
        comparator = Comparator.comparingLong(Event::getTimestamp);
    }

    @Override
    public void announceAnEvent(Event event) {
        eventQueue.orderedInsert(event, comparator);
    }

    @Override
    protected boolean hasNextEvent() {
        return !eventQueue.empty();
    }

    @Override
    protected Event getNextEvent() {
        return eventQueue.front();
    }

    @Override
    protected void resignFirstEvent() {
        eventQueue.pop();
    }

}


